<template>
  <div id="app">
    <!-- 如果当前路由是登录页，则不显示侧边栏等布局 -->
    <template v-if="$route.path === '/login'">
      <router-view></router-view>
    </template>
    
    <!-- 非登录页显示完整布局 -->
    <template v-else>
      <div class="app-container">
        <Sidebar @showMindView="handleShowMindView" />
        <div class="main-content">
          <router-view :mindViewData="mindViewData"></router-view>
        </div>
        <RightSidebar />
      </div>
    </template>
  </div>
</template>

<script>
import Sidebar from './components/Sidebar.vue'
import RightSidebar from './components/RightSidebar.vue'

export default {
  name: 'App',
  components: {
    Sidebar,
    RightSidebar
  },
  data() {
    return {
      mindViewData: null,
      industryName: null
    }
  },
  methods: {
    handleShowMindView(data,item) {
      // 添加防抖处理，防止短时间内多次调用
      if (this._mindViewDebounceTimer) {
        clearTimeout(this._mindViewDebounceTimer);
      }
      
      this._mindViewDebounceTimer = setTimeout(() => {
        console.log('[App] 处理思维导图数据:', data ? '有数据' : '无数据');
        this.mindViewData = data;
        this.industryName = item
        // 如果路由组件已经加载，确保数据传递
        if (this.$route.matched.length > 0 && this.$route.matched[0].instances.default) {
          this.$route.matched[0].instances.default.receiveMindViewData(data);
        }
      }, 300); // 300ms的防抖时间
    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

html, body {
  height: 100%;
  width: 100%;
}

#app, .app-container {
  height: 100vh;
  width: 100%;
  display: flex;
  overflow: hidden;
}

.main-content {
  flex: 1;
  background-color: #f7f7f8;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
</style> 